package dataproviders;

import items.Service;
import java.util.Iterator;
import java.util.List;
import org.apache.wicket.markup.repeater.data.IDataProvider;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.PropertyModel;

@SuppressWarnings("serial")
public class ServiceDataProvider implements IDataProvider{

	private List<Service> services;
	
	public ServiceDataProvider(List<Service> services){
		super();
		this.services = services;
	}
	
	@Override
	public void detach() {
		
	}

	@Override
	public Iterator iterator(int first, int count) {
		return this.services.subList(first, first + count).iterator();
	}

	@Override
	public int size() {
		return this.services.size();
	}

	@Override
	public IModel model(Object object) {
	   int index = this.services.indexOf(object);
	   return new PropertyModel<Service>(this.services, String.valueOf(index));
	}

	public List<Service> getServices() {
		return services;
	}

	public void setServices(List<Service> services) {
		this.services = services;
	}

}
